﻿Public Class UpdateItemMaster
    Inherits System.Web.UI.Page
    Public oCompany As SAPbobsCOM.Company
    Dim connect As New Connection()
    Dim oItemMasterData As New ItemMasterData
    Dim Str As String = ""
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            'Dim oITM As SAPbobsCOM.Items
            'Dim oRecordSetBP As SAPbobsCOM.Recordset
            'oITM = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
            'oRecordSetBP = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            'oRecordSetBP.DoQuery("(SELECT T1.[ItmsGrpNam] FROM [dbo].[OITB]  T1 ) UNION (SELECT  'SYSTEM'  [ItmsGrpNam] ) ORDER BY T1.[ItmsGrpNam]")
            'Dim i As Integer

            'If oRecordSetBP.RecordCount > 0 Then
            '    For i = 1 To oRecordSetBP.RecordCount
            '        ddlItemgroup.Items.Add(oRecordSetBP.Fields.Item(0).Value.ToString)
            '        oRecordSetBP.MoveNext()
            '    Next

            'Else
            '    ddlItemgroup.Items.Add("SYSTEM")
            'End If


        Catch ex As Exception
            LAB.Text = ex.Message
        End Try
    End Sub

    Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
        If Connection.bConnect = False Then
            connect.setDB(Session("UserID"), Session("Pwd"))
            Dim Str As String = connect.connectDB()
            If Str = "" Then
                UpdateItemMasterData()
            Else
                MsgBox(Str, MsgBoxStyle.OkOnly)
                ' LAB.Text = Str
                Exit Sub
            End If
        Else
            UpdateItemMasterData()
            'Response.Redirect("../Default.aspx")
        End If
    End Sub
    Public Sub UpdateItemMasterData()

        Try
            Dim Purch As String = ""
            Dim Sales As String = ""
            Dim Inv As String = ""
            If txtDescription.Text = "" Then
                LAB.Text = "Item Name Can't Be Empty!"
                Exit Sub
            Else
                If txtDescription.Text.Length > 100 Then
                    LAB.Text = "Item Name Can't Be Granter than 100 Characters!"
                    Exit Sub
                End If
            End If

            'If txtForeignName.Text.Length > 100 Then
            '    LAB.Text = "Item Name Can't Be Granter than 100 Characters!"
            '    Exit Sub
            'End If

            'If ddlItemgroup.Text = "" Then
            '    LAB.Text = "Item Group Name Can't Be Empty!"
            '    Exit Sub
            'End If
            'If ChkInventoryitem.Checked = True Then
            '    Inv = "Y"
            'Else
            '    Inv = "N"
            'End If
            'If ChkSalesitem.Checked = True Then
            '    Sales = "Y"
            'Else
            '    Sales = "N"
            'End If
            'If ChkPuchaseitem.Checked = True Then
            '    Purch = "Y"
            'Else
            '    Purch = "N"
            'End If
            'If Purch = "" And Sales = "" And Inv = "" Then
            '    LAB.Text = "Select one of the Inventory / Sales / Purchase Item Chek Box!"
            '    Exit Sub
            'End If
            If Connection.bConnect = False Then
                connect.setDB(Session("UserID"), Session("Pwd"))
                Str = connect.connectDB()
                If Str = "" Then
                    Str = oItemMasterData.Item_Update(txtSearch.Text, txtDescription.Text, "", "", Session("UserID"))
                    If Str = "Item Updated Successfully!" Then
                        LAB.ForeColor = Drawing.Color.Green
                        LAB.Text = Str
                        txtDescription.Text = ""
                        ' txtForeignName.Text = ""
                        txtSearch.Text = ""
                        ' TextBox3.Text = ""
                        LAB.ForeColor = Drawing.Color.Red
                    Else
                        LAB.ForeColor = Drawing.Color.Red
                        LAB.Text = Str
                    End If
                Else
                    LAB.Text = Str
                    Exit Sub
                End If
            Else

                Str = oItemMasterData.Item_Update(txtSearch.Text, txtDescription.Text, "", "", Session("UserID"))
                If Str = "Item Updated Successfully!" Then
                    LAB.ForeColor = Drawing.Color.Green
                    LAB.Text = Str
                    txtDescription.Text = ""
                    '                    txtForeignName.Text = ""
                    txtSearch.Text = ""
                    ' TextBox3.Text = ""
                    LAB.ForeColor = Drawing.Color.Red
                Else
                    LAB.ForeColor = Drawing.Color.Red
                    LAB.Text = Str
                End If


            End If
        Catch ex As Exception
            LAB.Text = ex.Message
        End Try
        'Dim oITM As SAPbobsCOM.Items
        'Dim oITB As SAPbobsCOM.ItemGroups
        'oITM = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
        'oITB = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItemGroups)

    End Sub

    Protected Sub btnFind_Click(sender As Object, e As EventArgs) Handles btnFind.Click
        Try
            Dim oITM As SAPbobsCOM.Items
            Dim oRecordSetBP As SAPbobsCOM.Recordset
            oITM = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
            oRecordSetBP = PublicVariable.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            oRecordSetBP.DoQuery("SELECT T0.[ItemCode], T0.[ItemName], T0.[FrgnName] FROM OITM T0 WHERE T0.[ItemCode] ='" & txtSearch.Text & "'")
            If oRecordSetBP.RecordCount > 0 Then
                txtDescription.Text = oRecordSetBP.Fields.Item(1).Value
                'txtForeignName.Text = oRecordSetBP.Fields.Item(2).Value
            Else
                LAB.Text = "Item Code Not Found!"
            End If
        Catch ex As Exception
            LAB.Text = ex.Message
        End Try
    End Sub
End Class